package zgs;
/*
 * 使用指定构造器实例化对象
 */
import java.lang.reflect.Constructor;
import java.util.Scanner;

public class ReflectDemo3 {
    public static void main(String[] args) throws Exception {
        Person person = new Person("李四",33);
        System.out.println(person);

        Scanner scan = new Scanner(System.in);
        System.out.println("请输入一个类名:");
        String className = scan.nextLine();
        Class cls = Class.forName(className);
//        Object obj = cls.newInstance();
//        System.out.println(obj);

        Constructor c = cls.getConstructor(String.class,int.class);
        Object obj = c.newInstance("王五",33);
        System.out.println(obj);

        Constructor c1 = cls.getConstructor(String.class);
        Object obj1 = c1.newInstance("赵六");
        System.out.println(obj1);





    }
}
